package com.字符串;

/**
 * 给定一个字符串，逐个翻转字符串中的每个单词。
 *
 *
 *
 * 示例 1：
 *
 * 输入: "the sky is blue"
 * 输出: "blue is sky the"
 */
public class 翻转字符串里的单词 {
    static class Solution {
        public String reverseWords(String s) {
            //\\s+ 匹配多个字符
            String[] str = s.split("\\s+");
            StringBuilder builder = new StringBuilder();
            for(int i = str.length-1;i>=0;i--){

                if(i == 0){
                    builder.append(str[i]);
                }
                else{
                    builder.append(str[i]).append(" ");
                }

            }
            return builder.toString().trim();
        }
    }

    public static void main(String[] args) {
        System.out.println("  "==" ");
        Solution solution = new Solution();
        System.out.println(solution.reverseWords("  hello world!  "));

    }
}
